import { NsNodeCmd, IGraphCommandService, NsGraph, NsEdgeCmd, XFlowEdgeCommands, NsGraphCmd, XFlowGraphCommands, } from '@antv/xflow'
import { XFlowNodeCommands, uuidv4 } from '@antv/xflow'

export const addNode = (cmd: IGraphCommandService, nodeConfig: NsGraph.INodeConfig) => {
  return cmd.executeCommand<NsNodeCmd.AddNode.IArgs>(XFlowNodeCommands.ADD_NODE.id, {
    nodeConfig: { ...nodeConfig, id: uuidv4(), width: 190, height: 32 },
  })
}

export const removeNode = (cmd: IGraphCommandService, nodeConfig: NsGraph.INodeConfig) => {
  return cmd.executeCommand<NsNodeCmd.DelNode.IArgs>(XFlowNodeCommands.DEL_NODE.id, {
    nodeConfig: { ...nodeConfig },
  })
}

export const addEdge = (cmd: IGraphCommandService, edgeConfig: NsGraph.IEdgeConfig) => {
  return cmd.executeCommand<NsEdgeCmd.AddEdge.IArgs>(XFlowEdgeCommands.ADD_EDGE.id, {
    edgeConfig: { ...edgeConfig, edgeContentWidth: 10, edgeContentHeigt: 100 },
  })
}

export const removeEdge = (cmd: IGraphCommandService, edgeConfig: NsGraph.IEdgeConfig) => {
  return cmd.executeCommand<NsEdgeCmd.DelEdge.IArgs>(XFlowEdgeCommands.DEL_EDGE.id, {
    edgeConfig: { ...edgeConfig },
  })
}

export const renderCanvas = (cmd: IGraphCommandService, graphData: NsGraph.IGraphData) => {
  /** 执行画布渲染命令 */
  console.log("画布渲染")
  cmd.executeCommand(XFlowGraphCommands.GRAPH_RENDER.id, {
    graphData,
  } as NsGraphCmd.GraphRender.IArgs)
} 